
<template>
  <div class="app-container" id="app">
    <h1 v-model="form.file_title">{{form.file_title}}</h1>
    <span id="file_content"></span>
  </div>
</template>

<script>

  import { listFile , getFile , addFile , updateFile ,delFile ,uploadFileImg ,updateFileEdit ,updateFileStatus} from "@/api/monitor/file";
  import { listChannel , getChannel , addChannel , updateChannel ,delChannel,getParentChannel} from "@/api/monitor/channel";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import Editor from '@/components/wangEditor'

  export default {
    name: "File",
    components: { Treeselect , Editor},
    data() {
      return {
        isClear: false,
        detail:"",
        user: {},
        sexs: [],
        option:[],
        id_card_type: [],
        status:[],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 默认密码
        initPassword: undefined,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 性别状态字典
        Options: [],
        // 岗位选项
        postOptions: [],
        // 角色选项
        roleOptions: [],
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,

        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 1000,
          name: undefined,
          status: undefined
        },
        params:{}
        /*        // 表单校验
                rules: {
                  userName: [
                    { required: true, message: "用户名称不能为空", trigger: "blur" }
                  ],
                  nickName: [
                    { required: true, message: "用户昵称不能为空", trigger: "blur" }
                  ],

                  email: [
                    {
                      type: "email",
                      message: "'请输入正确的邮箱地址",
                      trigger: ["blur", "change"]
                    }
                  ],
                  phonenumber: [
                    {
                      pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
                      message: "请输入正确的手机号码",
                      trigger: "blur"
                    }
                  ]
                }*/
      };
    },
    created() {
      const fileId = this.$route.params && this.$route.params.fileId;
      this.getFile(fileId);
      this.getListChannle();
    },

    methods: {
      submit () {
        updateFileEdit(this.form).then(rs =>{
          this.msgSuccess("修改成功");
        })
      },
      // 表单重置
      reset() {
        this.form = {
          file_title: undefined,
          file_content: undefined,
          template_id: undefined,
          channel_id: undefined,
        };
        this.resetForm("form");
      },
      //获取频道
      getListChannle(){
        listChannel(this.addDateRange(this.queryParams, this.dateRange)).then(rs =>{
          this.option = rs.data.items;
          console.log(this.option)
        })
      },
      getFile(fileId){
        getFile(fileId).then(rs =>{
          this.form = rs.data;
          if (rs.data.link!=null){
            window.open(rs.data.link)
          }
          document.getElementById("app").innerHTML = rs.data.file_content;
        })
      },
      /*文档附件上传*/
      handleAccessoryChangeIcon(file, fileList) {//选中文件触发的change事件
        console.log(file)
        const isJPG = file.raw.type === 'image/jpeg'
        const isPNG = file.raw.type === 'image/png'
        // const isLt2M = file.raw.size / 1024 / 1024 < 0.5  //限制上传文件的大小
        if (!isPNG && !isJPG) {
          this.$message.error('上传图片只能是 JPG/PNG 格式!')
          return false
        } else {
          this.form.accessory = URL.createObjectURL(file.raw);//赋值图片的url，用于图片回显功能
          this.uploadImg(file)//调用上传文件api接口
          this.$forceUpdate()
        }
      },
      uploadImg(file){//文件上传操作
        let formData=new FormData()
        formData.append('file',file.raw)
        uploadFileImg(formData).then(res=>{
          console.log(res)
          if (res.code == '20000') {
            this.msgSuccess(res.data.msg);
            this.form.accessory = res.data[0].url;
            console.log(this.form.accessory)
          }
        })
      },
      pass(){
        this.params.file_id=this.form.file_id;
        this.params.status = 2;
        updateFileStatus(this.params).then(res =>{
          this.msgSuccess("评审通过");
        })
      },
      refuse(){
        this.params.file_id=this.form.file_id;
        this.params.status = 3;
        updateFileStatus(this.params).then(res =>{
          this.msgError("拒绝通过");
        })
      }

    }

  };
</script>
<style>
  .myQuillEditor{
    height: 300px;
  }
</style>
